﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;

namespace Project.Yan.Net.DAL
{
    public interface IRepository<T> where T : class
    {
        /// <summary>
        /// 根据ID异步获取实体
        /// </summary>
        Task<T> GetByIdAsync(int id);

        /// <summary>
        /// 根据条件异步获取第一个实体
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<T> GetFirstOrDefaultAsync(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 异步获取所有实体
        /// </summary>
        Task<IEnumerable<T>> GetAllAsync();

        /// <summary>
        /// 根据条件异步查找实体
        /// </summary>
        Task<IEnumerable<T>> FindAsync(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 异步添加单个实体
        /// </summary>
        Task AddAsync(T entity);

        /// <summary>
        /// 异步添加多个实体
        /// </summary>
        Task AddRangeAsync(IEnumerable<T> entities);

        /// <summary>
        /// 更新实体
        /// </summary>
        void Update(T entity);

        /// <summary>
        /// 移除单个实体
        /// </summary>
        void Remove(T entity);

        /// <summary>
        /// 移除多个实体
        /// </summary>
        void RemoveRange(IEnumerable<T> entities);

        /// <summary>
        /// 异步保存更改
        /// </summary>
        Task<int> SaveChangesAsync();
    }

}
